package com.viphuli.app.tool.utils;

import android.app.Activity;

import com.viphuli.app.tool.bean.part.AccountUser;
import com.viphuli.app.tool.bean.part.ArrangeRecord;
import com.viphuli.app.tool.common.AccessTokenKeeper;
import com.viphuli.app.tool.common.Constants;
import com.viphuli.app.tool.common.Constants.ArrangeRecordType;
import com.viphuli.app.tool.fragment.ArrangeRecordDetailArrangeFragment;
import com.viphuli.app.tool.fragment.ArrangeRecordDetailExchangeFragment;

public class OtherUtils {
	
	public static long maxLength(long time) {

		String t = String.valueOf(time);
		t = t.substring(0, Math.min(Constants.TIME_STAMP_LENGTH, t.length()));

		return Long.valueOf(t);

	}

	public static long getNeedTime(long time) {

		StringBuilder sb = new StringBuilder(String.valueOf(time));

		int length = 13;
		int dif = length - String.valueOf(time).length();

		if (dif > 0) {
			for (int i = 0; i < dif; i++) {
				sb.append("0");
			}
		}

		return Long.parseLong(sb.toString());
	}

	public static void goToRecordDetails(Activity act, ArrangeRecord record) {

		AccessTokenKeeper tokenKeeper = AccessTokenKeeper.readAccessToken(act);

		if (tokenKeeper.isLogin()) {

			AccountUser user = tokenKeeper.getUser();

			ArrangeRecordType recordType = ArrangeRecordType.getType(record.getType());

			if (ArrangeRecordType.arrange.equals(recordType)) {

				ArrangeRecordDetailArrangeFragment.go(act, user.circleId(), record.getId());

			} else if (ArrangeRecordType.arrange_cancel.equals(recordType)) {

				ArrangeRecordDetailArrangeFragment.go(act, user.circleId(), record.getId());

			} else if (ArrangeRecordType.exchange.equals(recordType)) {

				ArrangeRecordDetailExchangeFragment.go(act, user.circleId(), record.getId());

			} else if (ArrangeRecordType.exchange_cancel.equals(recordType)) {

				ArrangeRecordDetailExchangeFragment.go(act, user.circleId(), record.getId());

			} else if (ArrangeRecordType.replace.equals(recordType)) {

				ArrangeRecordDetailExchangeFragment.go(act, user.circleId(), record.getId());

			} else if (ArrangeRecordType.replace_cancel.equals(recordType)) {

				ArrangeRecordDetailExchangeFragment.go(act, user.circleId(), record.getId());

			}

		}

	}

}
